#!/bin/bash

mv /etc/yum.repos.d/CentOS-Base.repo{,.bak}
#使用阿里源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
#删除阿里内网地址
sed -i '/aliyuncs.com/d' /etc/yum.repos.d/*.repo 

#创建ceph源
echo '#阿里ceph源
[ceph]
name=ceph
baseurl=http://mirrors.aliyun.com/ceph/rpm-luminous/el7/x86_64/
gpgcheck=0
[ceph-noarch]
name=cephnoarch
baseurl=http://mirrors.aliyun.com/ceph/rpm-luminous/el7/noarch/
gpgcheck=0
[ceph-source]
name=ceph-source
baseurl=http://mirrors.aliyun.com/ceph/rpm-luminous/el7/SRPMS/
gpgcheck=0
#'>/etc/yum.repos.d/ceph.repo

sed -i 's/0.centos.pool.ntp.org/182.92.12.11/' /etc/chrony.conf
sed -i 's/1.centos.pool.ntp.org/cn.ntp.org.cn/' /etc/chrony.conf
sed -i 's/2.centos.pool.ntp.org/120.25.108.11/' /etc/chrony.conf
sed -i 's/3.centos.pool.ntp.org/ntp.aliyun.com/' /etc/chrony.conf

systemctl start chronyd
systemctl enable chronyd

systemctl stop firewalld.service
systemctl disable firewalld.service
firewall-cmd --state
sed -i '/^SELINUX=.*/c SELINUX=disabled' /etc/selinux/config
sed -i 's/^SELINUXTYPE=.*/SELINUXTYPE=disabled/g' /etc/selinux/config
grep --color=auto '^SELINUX' /etc/selinux/config
setenforce 0

yum install -y ceph-deploy
mkdir my-cluster
cd my-cluster
ceph-deploy new ceph1 ceph2 ceph3

echo '
public network = 192.168.100.0/24
#cluster network = 192.168.100.0/24

mon_clock_drift_allowed = 2    
osd_journal_size = 4086
osd_pool_default_pg_num = 128
osd_pool_default_pgp_num = 128
osd pool default size = 2
osd pool default min size = 1
rbd_default_features = 1
client_quota = true
'>>./ceph.conf

ceph-deploy install --release luminous --repo-url https://mirrors.aliyun.com/ceph/rpm-luminous/el7/ --nogpgcheck ceph1 ceph2 ceph3
ceph-deploy mon create-initial
ceph-deploy admin ceph1 ceph2 ceph3
# #set server director as admin node
# mkdir /etc/ceph
# ceph-deploy admin director
ceph-deploy mgr create ceph1

ceph-deploy osd create --data /dev/sdb ceph1
ceph-deploy osd create --data /dev/sdb ceph2
ceph-deploy osd create --data /dev/sdb ceph3

# clear ceph
ceph-deploy purge ceph1 ceph2 ceph3
ceph-deploy purgedata ceph1 ceph2 ceph3
ceph-deploy forgetkeys
rm -rf ceph*

# ceph-deploy install --release luminous --repo-url https://mirrors.aliyun.com/ceph/rpm-luminous/el7/ server1

